package wheel;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;

public class Game {
	
	public static final String TEXT_FILES_DIRECTORY = ".\\input_output\\";
	static final public String PUNCTUATION = "[ -/:',&?!]";  // Regular Expression;
	static final public String SPLITTERS = "[ /:,?!]";     // Regular Expression;
	static final public String VOWELS = "AEIOUaeiou";
	static final public String CONSONANTS = "BCDFGHJKLMNPQRSTVWXYZbcdfghjklmnpqrstvwxyz";
	static final public int VOWEL_COST = 250;
	static final public String FREE_PLAY_STRING = 
			"FREE PLAY!  You may either choose a consonant for $%d, \n" +
			"            or select a free vowel, \n" +
			"            or try to solve the puzzle with no penalty.\n";
	
	
	public enum WedgeAction { BANKRUPT, MONEY, LOSE_TURN, FREE_PLAY };
	public enum ContestantAction { SPIN_WHEEL, BUY_VOWEL, SOLVE, WAVE_TO_VANNA, DOZE_OFF, 
	                               FREE_CONSONANT, FREE_VOWEL, FREE_GUESS, THINK };
	
	public static ArrayList<Phrase> phrases = new ArrayList<>(); 
		 
	public enum Category {
	   AROUND_THE_HOUSE,
	   AUTHOR_AND_TITLE,
	   BEFORE_AND_AFTER,
	   BEST_SELLER,
	   CHARACTERS,
	   CHARACTER,
	   CLASSIC_TV,
	   COLLEGE_LIFE,
	   EVENT,
	   EVENTS,
	   FAMILY,
	   FICTIONAL_FAMILY,
	   FICTIONAL_CHARACTER,
	   FICTIONAL_CHARACTERS,
	   FICTIONAL_PLACE,
	   FUN_AND_GAMES,
	   FOOD_AND_DRINK,
	   HEADLINE,
	   HUSBAND_AND_WIFE,
	   IN_THE_KITCHEN,
	   LANDMARK,
	   LIVING_THING,
	   LIVING_THINGS,
	   MOVIE_QUOTE,
	   MOVIE_QUOTES,
	   MOVIE_TITLE,
	   OCCUPATION,
	   OCCUPATIONS,
	   ON_THE_MAP,
	   PERSON,
	   PEOPLE,
	   PHRASE,
	   PLACE,
	   PLACES,
	   PROPER_NAME,
	   PROPER_NAMES,
	   QUOTATION,
	   ROCK_ON,
	   RHYME_TIME,
	   SAME_LETTER,
	   SAME_NAME,
	   SHOW_BIZ,
	   SONG_AND_ARTIST,
	   SONG_LYRICS,
	   SONG_TITLE,
	   SONG_TITLES,
	   STAR_AND_ROLE,
	   THE_SIXTIES,
	   THE_SEVENTIES,
	   THE_EIGHTIES,
	   THE_NINETIES,
	   THING,
	   THINGS,
	   TITLE,
	   TITLES,
	   TITLE_AND_AUTHOR,
	   TOTALLY_RANDOM,
	   TV_QUOTE,
	   TV_TITLE,
	   TV_TITLES,
	   WHAT_ARE_YOU_DOING,
	   WHERE_ARE_WE
	   };
	   
	   
	   private static void loadPhrases() {
   			try {
				BufferedReader in = new BufferedReader(new FileReader(TEXT_FILES_DIRECTORY + "phrases.txt"));
				try {
					String line = in.readLine();
					while (line != null) {
						String element[] = line.split(",");
						phrases.add(new Phrase(element[0], Category.valueOf(element[1])));
						line = in.readLine();
					}
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
   		}
   		
   		/**
   		 * initializePhrases will create a series of phrases that can be used for testing purposes
   		 */
   		private static void initializePhrases() {
   			phrases.add(new Phrase("Hailing a Taxi", Game.Category.WHAT_ARE_YOU_DOING)); 
   			phrases.add(new Phrase("Counting my Number of Vacation Days", Game.Category.WHAT_ARE_YOU_DOING));
   			phrases.add(new Phrase("Escaping from all the Hustle and Bustle", Game.Category.WHAT_ARE_YOU_DOING));
   			phrases.add(new Phrase("Unwritten Rules", Game.Category.THINGS));
   			phrases.add(new Phrase("Pudgy Cheeks", Game.Category.THINGS));
   			phrases.add(new Phrase("Pinocchio and Jiminy Cricket", Game.Category.CHARACTERS));
   			phrases.add(new Phrase("Ferocious Tigers", Game.Category.LIVING_THINGS));
   			phrases.add(new Phrase("Quarterbacks and Linebackers", Game.Category.OCCUPATIONS));
   			phrases.add(new Phrase("The Bachelor and the Bachelorette", Game.Category.TV_TITLES));
   			phrases.add(new Phrase("Shall We Play a Game?", Game.Category.MOVIE_QUOTE));
   			phrases.add(new Phrase("That's Entertainment", Game.Category.SHOW_BIZ));
   			phrases.add(new Phrase("Ballpoint & Bull Pen", Game.Category.SAME_NAME));
   			phrases.add(new Phrase("Half-Hour Television Program", Game.Category.SHOW_BIZ));
   			phrases.add(new Phrase("Incomplete is Pink Slowly", Game.Category.TOTALLY_RANDOM));
   			phrases.add(new Phrase("Babies Masculine Without More Jumping", Game.Category.TOTALLY_RANDOM));
   			phrases.add(new Phrase("Maul Anomaly Turning Into Sour Pigs", Game.Category.TOTALLY_RANDOM));
   			phrases.add(new Phrase("Confused Quicksand Life Of", Game.Category.TOTALLY_RANDOM));
   			phrases.add(new Phrase("Unequiovacable and Mysterious Salamanders", Game.Category.TOTALLY_RANDOM));
   			phrases.add(new Phrase("The Soldier Waxed the Harbor Birdhouse", Game.Category.TOTALLY_RANDOM));
   			phrases.add(new Phrase("Seven Databases never will Orangutan", Game.Category.TOTALLY_RANDOM));
   			phrases.add(new Phrase("Darth Vader Luke Skywalker and Princess Leia", Game.Category.FICTIONAL_FAMILY));
   			phrases.add(new Phrase("No Deposit No Return of the Jedi", Game.Category.BEFORE_AND_AFTER));
   			phrases.add(new Phrase("Gigli", Game.Category.MOVIE_TITLE));
   			phrases.add(new Phrase("Inception", Game.Category.MOVIE_TITLE));
   			phrases.add(new Phrase("Anchorman", Game.Category.MOVIE_TITLE));
   			phrases.add(new Phrase("Sly as a Fox", Game.Category.PHRASE));
   			phrases.add(new Phrase("Rent", Game.Category.MOVIE_TITLE));
   			phrases.add(new Phrase("Ellis Island", Game.Category.LANDMARK));
   			phrases.add(new Phrase("Aristotle", Game.Category.PERSON));
   			phrases.add(new Phrase("Spicy Buffalo Wings", Game.Category.FOOD_AND_DRINK));
   			phrases.add(new Phrase("Delightful Downtown Deli", Game.Category.SAME_LETTER));
   			phrases.add(new Phrase("Manhattan Clam Chowder", Game.Category.FOOD_AND_DRINK));
   			phrases.add(new Phrase("In the Driver's Seat", Game.Category.PHRASE));
   		}
   		
   		public static Phrase getRandomPhrase() {
   			loadPhrases();
   			return phrases.get((int) (Math.random()*(phrases.size())));
   		}
   		
   		public static Phrase getPhrase(int i) {
   			initializePhrases();
   			return phrases.get(i);
   		}
   		
   		public static void makeSound(String soundType) {
   			SoundPlayer audio = new SoundPlayer();
   			switch (soundType) {
   			case "bankrupt":
   				audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "bankrupt.wav");
   				break;
   			case "new puzzle":
   				audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "newPuzzle.wav");
   				break;
   			case "ding":
   				audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "ding.wav");
   				break;
   			case "only vowels":
   				audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "vowels.wav");
   				break;
   			case "buzzer":
   				audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "buzzer.wav");
   				break;
   			case "applause":
   				audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "applause.wav");
   				break;
   			case "free play":
   				audio.playSound(SoundPlayer.SOUND_FILES_DIRECTORY + "freeplay.wav");
   				break;
   			}
   		}
   		
   	public static boolean isConsonant(char c) {
   		for(int i=0; i<CONSONANTS.length(); i++) {
   			if (CONSONANTS.charAt(i) == c)
   				return true;
   		}
   		return false;
   	}
   	
   	public static boolean isVowel(char c) {
   		for(int i=0; i<VOWELS.length(); i++) {
   			if (VOWELS.charAt(i) == c)
   				return true;
   		}
   		return false;
   	}
}
